//
//  WPFirstTableFooterView.m
//  wobingwoyi
//
//  Created by WGP on 2016/11/16.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPFirstTableFooterView.h"

@interface WPFirstTableFooterView ()

@property(nonatomic,strong)UILabel *editeLabel;
@property(nonatomic,strong)UIButton *btn;

@end
@implementation WPFirstTableFooterView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self setupUI];
    }
    return self;
}

-(void)setupUI
{
    [self topView];
    [self lines];
    [self editeLabel];
    [self btn];
}

-(UIView *)topView
{
    if (_topView == nil)
    {
        _topView = [UIView new];
        _topView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_topView];
        
        [_topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self);
            make.height.mas_equalTo(44);
        }];
    }
    return _topView;
}

-(void)lines
{
    UIImageView *topLineView = [UIImageView lineImageView];
    self.topLineView = topLineView;
    UIImageView *bottomLineView = [UIImageView lineImageView];
    
    [self.topView addSubview:topLineView];
    [self.topView addSubview:bottomLineView];
    
    [topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.topView);
        make.height.mas_equalTo(0.5);
    }];
    
    [bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.topView);
        make.height.mas_equalTo(0.5);
    }];
}

-(UIButton *)btn
{
    if (_btn == nil)
    {
        _btn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        _btn.backgroundColor = [UIColor clearColor];
        [_btn setTitleColor:GLobalFontColor forState:UIControlStateNormal];
        [_btn addTarget:self action:@selector(coverBtnDidClick:) forControlEvents:UIControlEventTouchDown];
        [self addSubview:_btn];
        
        [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(_topView);
            make.top.equalTo(_topView).offset(1);
            make.bottom.equalTo(_topView).offset(-1);
        }];
    }
    return _btn;
}

-(UILabel *)editeLabel
{
    if(_editeLabel == nil)
    {
        _editeLabel = [UILabel new];
        _editeLabel.font = [UIFont systemFontOfSize:15];
        _editeLabel.textColor = GLobalFontColor;
        _editeLabel.text = @"添加诊断";
        [self.topView addSubview:_editeLabel];
        
        [_editeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self.topView);
        }];
        
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"addCase_icon"]];
        [_topView addSubview:imageView];
        
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_topView);
            make.right.equalTo(_editeLabel.mas_left).offset(-8);
        }];
        
        _timeLabel = [UILabel new];
        _timeLabel.textColor = GLobalFontColor;
        _timeLabel.font = [UIFont systemFontOfSize:15];
        [_topView addSubview:_timeLabel];
        
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_topView).offset(10);
            make.centerY.equalTo(_topView);
        }];
    }
    return _editeLabel;
}

-(void)setAddTitle:(NSString *)addTitle
{
    _addTitle = addTitle;
    
    self.editeLabel.text = addTitle;
}

-(void)setIndex:(NSUInteger)index
{
    _index  = index;
}

-(void)coverBtnDidClick:(UIButton *)btn
{
    if (self.addDiseaseBlick)
    {
        self.addDiseaseBlick();
    }
}

@end
